<?php
$objXajax->registerFunction("fmfrmreportcancelroom_load");

function fmfrmreportcancelroom_load($dateFrom,$dateTo){     

    global $lang;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
    $arrData = fmfrmreportcancelroom_createArray($dateFrom,$dateTo);
    //echo '<pre>'; print_r($arrData); die();
    $count = count($arrData);
     
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('templates/'.$lang.'/customer/fm_reportcancelroom_grid.html');
    $oTbs->MergeBlock('blk_data', $arrData); 
    $oTbs->Show(TBS_NOTHING);  
    $objResponse->addAssign('fmfrmreportcancelroom_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('fmfrmreportcancelroom_tbl',true);");  
    $objResponse->addScript('changeWaiting(1);');                     
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
}

function fmfrmreportcancelroom_createArray($dateFrom,$dateTo){
    global $objDbUpdate,$tbl_postfix;
    $addCondition = '';   
    
    $sql = "  select r.name as roomname,h.timestart as timebegin,h.timeend as timeend ,
   TIMESTAMPDIFF(MINUTE,h.timestart,h.timeend) as timerent,reason_cancel,u1.username as userstart ,u2.username as userend  
   from fm_current_book$tbl_postfix as h join fm_room r ON h.room_id = r.id left join tbl_user as u1 ON h.user_created = u1.id left join tbl_user as u2 ON h.user_cancel = u2.id
     where  datediff('$dateFrom',h.timeend)<=0 and datediff('$dateTo',h.timeend)>=0 and h.flg_cancel = 1 order by timeend"; 
    $arr = array();
   // echo  $sql;
    try{
        $arr = $objDbUpdate->GetArray($sql);
        $count =  count($arr);
        //echo '<pre>'; print_r($arr); die();   
        for($i=0;$i<$count;$i++){ 
            $arr[$i]['timerent']= ConvertTimeToHM($arr[$i]['timerent']) ; 
        } 
    }
    catch(Exception $e){
        $arr = array();
    } 
    return  $arr  ;
} 


# end region process data
?>
